import { useModel } from "umi";

import AddCategory from "../components/category/AddCategory";
import AddSubCategory from "../components/category/AddSubCategory";
import EditCategory from "../components/category/EditCategory";


const useHelperCategory = () => {
    const { setModalVisible, setModalTitle, setModalWidth, setModalComponent, setModalStyle } = useModel("global.modal");

    const addCategoryModle = ({ reloadData }) => {
        setModalTitle("新增商品品类");
        setModalVisible(true);
        setModalWidth(500);
        setModalStyle({ top: 100 });
        setModalComponent(<AddCategory reloadData={reloadData} />);
    };

    const addSubCategoryModle = ({ item, reloadData }) => {
        setModalTitle("添加下级商品品类");
        setModalVisible(true);
        setModalWidth(600);
        setModalStyle({ top: 100 });
        setModalComponent(<AddSubCategory item={item} reloadData={reloadData} />);
    };

    const openEditCategoryModle = ({ item, reloadData }) => {
        setModalTitle("编辑商品品类");
        setModalVisible(true);
        setModalWidth(500);
        setModalStyle({ top: 100 });
        setModalComponent(<EditCategory item={item} reloadData={reloadData} />);
    };


    return { addCategoryModle, addSubCategoryModle, openEditCategoryModle };
};

export default useHelperCategory;
